package src

import (
	"errors"
	"net/http"
)

type User struct {
	Id        int    `json:"id"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	UserName  string `json:"user_name"`
	Address   string `json:"address"`
}

//需要实现这个方法，才能 render输出
func (user *User) Render(w http.ResponseWriter, r *http.Request) error {
	return nil
}

type UserRequest struct {
	Id        int    `json:"id"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	UserName  string `json:"user_name"`
	Address   string `json:"address"`
}

func (a *UserRequest) Bind(r *http.Request) error {
	// a.Article is nil if no Article fields are sent in the request. Return an
	// error to avoid a nil pointer dereference.
	if a.FirstName == "" {
		return errors.New("missing required Article fields.")
	}

	return nil
}
